﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Criterion;
using ShopSpace.Core.Query;

namespace ShopSpace.Core.Specification.Impl
{
	public class PersonAvailableForProject : CompositeSpecification<Person>
	{
		public Project Project
		{
			get;
			set;
		}

		public PersonAvailableForProject(Project project)
		{
			this.Project = project;
		}

		private DetachedCriteria ToDetatchedCriteria()
		{
			DetachedCriteria alreadOnProject = DetachedCriteria.For<ProjectPerson>()
				.Add(Expression.Eq("Project.Id", this.Project.Id))
				.SetProjection(Projections.Property("Person.Id"));

			DetachedCriteria criteria = DetachedCriteria.For<Person>()
				.Add(Subqueries.PropertyNotIn("Id", alreadOnProject))
				.Add(Expression.Eq("PortalId", this.Project.PortalId))
				.AddOrder(Order.Asc("DisplayName"));

			return criteria;
		}

		public override bool IsSatisfiedBy(Person instance)
		{
			throw new NotImplementedException();
		}

		public override QueryBuilder<Person> AsQueryBuilder()
		{
			throw new NotImplementedException();
		}
	}
}
